/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//		File Name		:		CMainMenuState.h
//
//		Author			:		Kevin Jordan
//
//		Purpose			:		A header for all functions and members of the Main Menu
//
//		Dates			:		Written( Feb 12, 2011 ) by Kevin Jordan		LastUpdate( Feb 12, 2011  ) by Kevin Jordan 
//	
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "CMainMenuState.h"
#include "CDocksLevelState.h"
#include "CGamePlayState.h"
#include "CSaveOrLoadState.h"
#include "SGD Wrappers/CSGD_DirectInput.h"
#include "SGD Wrappers/CSGD_Direct3D.h"
#include "SGD Wrappers/CSGD_TextureManager.h"
#include "CGame.h"
#include "CHubState.h"
#include "VIN_BitMapFont.h"
#include "COptionsState.h"
#include "CCredits.h"
#include "CHighScoreState.h"

CMainMenuState::CMainMenuState()
{
	m_nSelection = 0;
	ImageID = -1;
	newbie = true;
	m_bFirstEnter = true;
}

CMainMenuState::~CMainMenuState()
{

}


void CMainMenuState::Enter()
{
	if(CHubState::GetInstance()->GetPlayer())
	{
		//		CHubState::GetInstance()->GetPlayer()->Release();
	}
	if( m_bFirstEnter )
	{
		COptionsMenu::GetInstance()->LoadDefaults();
		m_bFirstEnter = false;
	}
	ImageID = CSGD_TextureManager::GetInstance()->LoadTexture("./resource/Graphics/Rio.png");
	VIN_SoundManager::GetInstance()->PlayBGM(BGM_TITLESCREEN);

	CursorID = CSGD_TextureManager::GetInstance()->LoadTexture("./resource/Graphics/Pointer.png");
}


void CMainMenuState::Exit()
{

}

CMainMenuState* CMainMenuState::GetInstance()
{
	static CMainMenuState instance;
	return &instance;
}

void CMainMenuState::Render()
{
	CSGD_Direct3D* pD3D = CSGD_Direct3D::GetInstance();
	CSGD_TextureManager* pTM = CSGD_TextureManager::GetInstance();
	VIN_BitMapFont* pBF = VIN_BitMapFont::GetInstance();
	pTM->Draw(ImageID, 0,0);

	RECT MenuRect;
	SetRect( &MenuRect, 200, 100, 600, 450 );

	RECT MenuRectII;
	SetRect( &MenuRectII, 185, 85, 615, 465 );

	pD3D->GetSprite()->Flush();
	pD3D->DrawRect( MenuRectII, 255,255,255);
	pD3D->DrawRect( MenuRect, 0,0,0);

	pBF->Render("Start Game", 350,150,.75f, D3DCOLOR_ARGB(255,255,0,0),0);
	pBF->Render("Options", 350,200,.75f, D3DCOLOR_ARGB(255,255,0,0),0);
	pBF->Render("Credits", 350,250,.75f, D3DCOLOR_ARGB(255,255,0,0),0);
	pBF->Render("High Scores", 350,300,.75f, D3DCOLOR_ARGB(255,255,0,0),0);
	pBF->Render("How To", 350,350,.75f, D3DCOLOR_ARGB(255,255,0,0),0);
	pBF->Render("Exit", 350,400,.75f, D3DCOLOR_ARGB(255,255,0,0),0);

	switch(m_nSelection)
	{
	case 0:
		{
			pTM->Draw(CursorID, 320,150);
		}
		break;
	case 1:
		{
			pTM->Draw(CursorID, 320,200);
		}
		break;
	case 2:
		{
			pTM->Draw(CursorID, 320,250);
		}
		break;
	case 3:
		{
			pTM->Draw(CursorID, 320,300);
		}
		break;
	case 4:
		{
			pTM->Draw(CursorID, 320,350);
		}
		break;
	case 5:
		{
			pTM->Draw(CursorID, 320,400);
		}
		break;
	}

}

bool CMainMenuState::Input()
{

	CSGD_DirectInput*	pDI = CSGD_DirectInput::GetInstance();
	CGame*				pGameState = CGame::GetInstance();

	if( pDI->KeyPressed( DIK_UP ) || CSGD_DirectInput::GetInstance()->JoystickGetLStickDirPressed(DIR_UP) ||
		CSGD_DirectInput::GetInstance()->JoystickDPadPressed(DIR_UP))
	{
		VIN_SoundManager::GetInstance()->PlayMenuSelect();
		m_nSelection--;
		if( m_nSelection < 0 )
			m_nSelection = 5;
	}

	if( pDI->KeyPressed( DIK_DOWN ) || CSGD_DirectInput::GetInstance()->JoystickGetLStickDirPressed(DIR_DOWN) || 
		CSGD_DirectInput::GetInstance()->JoystickDPadPressed(DIR_DOWN) )
	{
		VIN_SoundManager::GetInstance()->PlayMenuSelect();
		m_nSelection++;
		if( m_nSelection > 5 )
			m_nSelection = 0;
	}

	if( pDI->KeyPressed( DIK_RETURN ) || CSGD_DirectInput::GetInstance()->JoystickButtonPressed(1) )
	{
		VIN_SoundManager::GetInstance()->PlayMenuConfirm();

		switch( m_nSelection )
		{
		case 0:
			{
				//Change the State to GamePlayState
				if(newbie)
				{
					pGameState->ChangeState( CDocksLevelState::GetInstance());
					newbie = false;
				}
				else
					pGameState->ChangeState( CHubState::GetInstance());


			}
			break;

		case 1:
			{
				//Change the State to OptionsState
				pGameState->ChangeState(COptionsMenu::GetInstance());

			}
			break;

		case 2:
			{
				//Change the State to GamePlayState
				pGameState->ChangeState( CCreditsState::GetInstance());
			}
			break;

		case 3:
			{
				pGameState->ChangeState( CHighScoreState::GetInstance() );
				
			}
			break;
		case 4:
			{
				//Change the State to GamePlayState
				newbie = true;
				pGameState->ChangeState( CDocksLevelState::GetInstance());
			}
			break;

		case 5:
			{
				PostQuitMessage(0);

			}
			break;
		}
	}
	return true;
}


void CMainMenuState::Update(float fElapsedTime)
{

}